package tech.aistar.day04;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 本类用来演示:
 *
 * @author: success
 * @date: 2022/7/21 9:51 上午
 */
public class SpringBean {
    public static void main(String[] args) {

        System.out.println(int.class);

        //spring - xml解析技术 - sax,dom4j,jaxb
        //dom4j - 经典
        //读取applicationContext.xml
        //有办法取出有效信息tech.aistar.day04.Customer
        String className = "tech.aistar.day04.Customer";

        //反射创建这个类的对象
        try {
            Class<?> c = Class.forName(className);

            Customer customer = (Customer) c.newInstance();
            //xml解析 - id
            String id = "id";
            String sid = "set"+"Id";

            //反射获取setId对应的Method实例
            Method m = c.getDeclaredMethod(sid,int.class);

            m.invoke(customer,100); // 调用setId方法

            System.out.println(customer.getId());

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
